package ru.cod.rs.service;

import ru.cod.rs.manager.DrawManager;
import ru.cod.rs.views.GameView;
import android.graphics.Canvas;
import android.util.Log;
import android.view.SurfaceHolder;

public class DrawManagerImpl extends AbstractManagerImpl implements DrawManager{
	
	protected SurfaceHolder sHolder;
	protected GameView view;
	
	public DrawManagerImpl(GameView v) {
		super(v.getContext());
		view=v;
		sHolder=view.getHolder();
	}
	

	@Override
	public void execute() {
		Log.i("EXECUTE Method � DRAWMANAGER","");
		Canvas canvas = null;
			try {
				synchronized(sHolder) {
					canvas=sHolder.lockCanvas();
					update();
					draw(canvas);
				}
			} catch(Exception e) {
				e.printStackTrace();
			} finally {
				if(canvas!=null) {
					sHolder.unlockCanvasAndPost(canvas);
				}
			}
	}

	public void draw(Canvas c) {
		//Empty because of abstract
		Log.i("DRAW METHOD � DRAWMANAGER","");
	}
	protected void update() {
		Log.i("UPDATE METHOD � DRAWMANAGER","");
	}

	public boolean isSkip() {
		return !sHolder.getSurface().isValid();
	}

}
